<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : shop_brand.php   FILE_PATH : E:\web\mulitishop\home\shop_brand.php
 * 品牌商城
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 
 * @package 
 * @subpackage 
 * @version Thu Dec 06 10:47:35 CST 2007
 */

require ("../global.inc.php");

class ShopBrandIndex extends CommonFrameWork{
	/**
	 * 商铺对象
	 *
	 * @var obj
	 */
	var $obj_shop;
	/**
	 * 商铺分类对象
	 *
	 * @var obj
	 */
	var $obj_shopcategory;
	/**
	 * 商品对象
	 *
	 * @var obj
	 */
	var $obj_product;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	
	function main(){
		/**
		 * 创建商铺对象
		 */
		if (!is_object($this->obj_shop)){
			require_once("shop.class.php");
			$this->obj_shop = new ShopClass();
		}
		/**
		 * 创建商铺分类对象
		 */
		if (!is_object($this->obj_shopcategory)){
			require_once("shopcategory.class.php");
			$this->obj_shopcategory = new ShopCategoryClass();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("home");

		/**
		 * 语言包
		 */
		$this->getlang("shop");

		switch ($this->_input['action']){
			default:
				$this->_list();
		}
	}
	
	/**
	 * 品牌商城
	 */
	function _list(){
		/**
		 * 初始化分页类
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		/**
		 * 取商店分类一级
		 */
		$category_array = $this->obj_shopcategory->getLevelCategory(1,'');
		
		/*取所有商店*/
		$this->obj_page->pagebarnum(6);
		$shop_all = $this->obj_shop->getShopList($obj_condition, $this->obj_page);
		/*服饰运动*//*值为类别ID*/
		$shop_class['sports'] = 6;
		/*美容珠宝*/
		$shop_class['cosmetics'] = 2;
		/*数码*/
		$shop_class['digital'] = 4;
		/*家居母婴*/
		$shop_class['home'] = 3;
		/*图书音像*/
		$shop_class['culture'] = 7;
		/*对商店进行分类*/
		if (is_array($shop_class)){
			foreach ($shop_class as $k => $v){
				/*取商店*/
				$this->obj_page->pagebarnum(6);
				$obj_condition['slcShopClass'] = $v;
				$shop_array[$k] = $this->obj_shop->getShopList($obj_condition, $this->obj_page);
			}
		}

		
		/**
		 * 商品分类
		 */
		require_once("productclass.class.php");
		$obj_search_cate = new ProductCategoryClass();
		$id = 0;
		$deep = 1;
		$search_cate = $obj_search_cate->listCateById($id, $deep);
		/**
		 * 取商品分类
		 */
		$product_all_class = $obj_search_cate->listCateById(0,2);
		/*服饰运动*/
		$product_class['sports'] = array(33,35,12);
		/*美容珠宝*/
		$product_class['cosmetics'] = array(30,46,29);
		/*数码*/
		$product_class['digital'] = array(3,2,7);
		/*家居母婴*/
		$product_class['home'] = array(38,17,37);
		/*图书音像*/
		$product_class['culture'] = array(41,43,22);
		/*循环栏目*/
		if (is_array($product_class)){
			foreach ($product_class as $k => $v){
				/*循环栏目下的商品分类ID*/
				foreach ($v as $k2 => $v2){
					/*循环商品的全部分类*/
					foreach ($product_all_class as $v3){
						/*判断栏目下的商品分类ID是否存在*/
						if ($v3['id'] == $v2){
							/*如果存在，该分类信息进行赋值*/
							$product_class[$k][$k2] = $v3;
							/*取该商品分类ID的下一级类别内容*/
							foreach ($product_all_class as $v4){
								/*判断父ID是否和该商品分类ID相等*/
								if ($v4['parentId'] == $v2){
									$product_class[$k][$k2]['class'][] = $v4;
								}
							}
						}
					}
				}
			}
		}
		/**
		 * 创建商品对象
		 */
		if (!is_object($this->obj_product)){
			require_once("product.class.php");
			$this->obj_product = new ProductClass();
		}
		/**
		 * 取所有商品
		 */
		$product = $this->obj_product->getProductList($obj_condition, &$obj_page);
		/**
		 * 把商品按照$product_class类别分类
		 */
		$product_array = array();
		if (is_array($product_class)){
			/*循环商品*/
			foreach ($product as $k => $v){
				/*循环商品类别*/
				foreach ($product_class as $k2 => $v2){
					/*循环下一级类别*/
					foreach ($v2 as $k3 => $v3){
						/*判断取的商品个数*/
						if (count($product_array[$k2])<5){
							if ($v3['id'] == $v['pc_id']){
								$product_array[$k2][] = $v;
							}else {
								if (is_array($v3['class'])){
									/*循环下一级类别*/
									foreach ($v3['class'] as $k4 => $v4){
										if ($v4['id'] == $v['pc_id']){
											$product_array[$k2][] = $v;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		/**
		 * 页面输出
		 */
		$this->output("site_url", $this->_configinfo['websit']['site_url']);
		$this->output("search_cate", Common::showForm_Select2("searchcate", "", "", $search_cate));
		$this->output('category_array',$category_array);
		$this->output('product_class',$product_class);/*商品类别*/
		$this->output('product_array',$product_array);/*商品信息*/
		$this->output('shop_array',$shop_array);/*商品信息*/
		/*页头导航的样式判断*/
		$this->output('search_header_sign',  '2');		
		$this->showpage('shop.brand');
	}
	
}

$shop_brand = new ShopBrandIndex();
$shop_brand->main();
unset($shop_brand);
?>